home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / ma93.lha / MenuVerify / MenuVerify.txt < prev   
Encoding:
Text File  |  1993-05-19  |  13.2 KB  |  270 lines

  1. (c) Copyright 1993 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7. Menu Verify Handling
  8.  
  9.  
  10. by John Orr and Peter Cherna
  11.  
  12.  
  13. Menu verify has been a part of Intuition for a long time, so it may
  14. seem a bit odd to see an Amiga Mail article on the subject.
  15. Unfortunately, the ``Intuition Menus'' chapter of the Amiga ROM Kernel
  16. Reference Manual: Libraries is a bit unclear on the subject.  It does
  17. not sufficiently cover why an application would need to use this
  18. feature and how an application should handle it.
  19.  
  20.  
  21. Menu Verify
  22.  
  23. When the user tries to pull down the active window's menu, Intuition
  24. offers applications a chance to prepare for the menu operation.
  25. Intuition delays displaying any menus until the application has
  26. finished its preparations for the menu operation.  This feature is
  27. known as menu verify.
  28.  
  29. Menu verification works using the IDCMP mechanism.  For an Intuition
  30. screen, when the user triggers Intuition into drawing the menu,
  31. Intuition sends an IDCMP_MENUVERIFY message to every window on that
  32. screen that asked to hear about menu verify events.  Intuition will not
  33. display the menus until it gets back all the IDCMP_MENUVERIFY messages.
  34.  
  35. If the active window uses menu verification, Intuition gives that
  36. window the option to cancel the menu operation.  This allows the
  37. application to selectively use the menu button to activate the menu or
  38. to perform some other function.
  39.  
  40. Beginning with V36, Intuition introduced a time out on menu verify
  41. operations.  If the active window's application takes too long to
  42. respond to the IDCMP_MENUVERIFY message, Intuition will cancel the menu
  43. operation.  This feature helps avoid some deadlocks that can occur
  44. while Intuition is waiting on the active window.  This feature applies
  45. only to the active window; Intuition will wait indefinitely for the
  46. IDCMP_MENUVERIFY message from an inactive window.
  47.  
  48.  
  49. Reasons to Use Menu Verify
  50.  
  51. The primary purpose of the menu verify feature is to arbitrate access
  52. to screen resources.  There are really only two screen resources that
  53. an application might need to use directly, the palette and the bitmap.
  54.  
  55. Some applications need as many pens as possible, so they change the
  56. color values of the pens that Intuition uses to render the menus.  This
  57. can present a problem if the application happens to alter the menu pen
  58. colors so that the menu's foreground color is difficult (if not
  59. impossible) to see against the background color.  The menu items will
  60. be unreadable to the user.
  61.  
  62. To prevent this problem, the application has to restore the original
  63. pen colors when the user pulls down the menu.  The application can do
  64. this using menu verify.  When the user hits the menu button, Intuition
  65. sends the application a menu verify message.  When the application
  66. receives this message, it restores the menu colors and then returns the
  67. IDCMP_MENUVERIFY message so Intuition can properly render the menus.
  68. When the menu operation is over, Intuition will send a ``conclusion''
  69. IDCMP message.  The ``conclusion'' message is covered later in this
  70. article.
  71.  
  72. Another reason to use menu verify is to arbitrate rendering access to
  73. an Intuition Screen's bitmap.  While Intuition is displaying the menus,
  74. the application must not render directly to the screen's bitmap because
  75. the application could draw over the menus.  The application must wait
  76. until the menu operation is over to resume rendering.
  77.  
  78. This raises some important questions.  Why render into a screen's
  79. bitmap (Screen-> RastPort.BitMap)?  Shouldn't I render into a window
  80. instead?
  81.  
  82. The quick answer is: ``render into a window's rastport instead of
  83. rendering directly into a screen's bitmap''.  Rendering to a window's
  84. rastport offers several advantages over rendering directly to the
  85. screen's bitmap.  The window offers the application efficient clipping,
  86. making the application simpler because it doesn't need to worry about
  87. rendering into rectangular bounds.  The window also supports a layered
  88. display, so the application can ignore the consequences of arbitrating
  89. access to the screen's bitmap.
  90.  
  91. There are some cases where, arguably, it might be advantageous for an
  92. application to render directly into a screen's bitmap.  Rendering into
  93. a screen's bitmap versus rendering to a window's rastport offers a
  94. slight improvement in performance.  Part of this improvement is due to
  95. the lack of clipping on a screen's bitmap, which the window provides,
  96. so the performance improvement is questionable if you still need to
  97. perform clipping.
  98.  
  99. One case where an application has to render into a screen's bitmap is
  100. when graphics functions that operate below the layers level.  For
  101. example blitter objects (BOBs) operate below the layers level.  If the
  102. application is operating below the layers level, it can't render to a
  103. windowed display.
  104.  
  105.  
  106. Reasons Not to Use Menu Verify
  107.  
  108. One feature of Intuition menus is that the user can toggle a menu item
  109. between a selected ``checked'' state and an unselected ``unchecked''
  110. state.  Intuition keeps track of the state, so the application only has
  111. to read the state from the MenuItem structure.  In some cases, the
  112. state of the menu item can be affected by something besides the user
  113. performing menu operations, so the application has to explicitly change
  114. the state of the menu item.
  115.  
  116. Some applications use the menu verify feature as a mechanism for
  117. updating the state of the menu items.  When such an application
  118. receives the IDCMP_MENUVERIFY message, it updates the checked flag of
  119. the menu items and then returns the menu verify message.  Some
  120. applications also use this method to manage the enabled and disabled
  121. state of a menu item.
  122.  
  123. Although this method works, it should not be necessary to interrupt the
  124. menu event.  Almost all applications should be able to keep their menu
  125. states current using ResetMenuStrip().  It is also possible to use
  126. SetMenuStrip(), but since ResetMenuStrip() is considerably faster than
  127. SetMenuStrip(), ResetMenuStrip() is better.  See the Autodoc for
  128. ResetMenuStrip() for more details.
  129.  
  130. Some people may think one potential use for menu verify is to assign an
  131. alternative meaning to the right mouse button.  For example, when the
  132. pointer is not within the title bar of a screen, some paint packages
  133. use the right mouse button to paint using the background color.  Using
  134. menu verify, it is possible for a application to intercept the menu
  135. verify event, checking to see if the pointer is within the title bar.
  136. If it isn't, the application cancels the menu event.  After cancelling
  137. the menu event, Intuition will send a right button down event, which
  138. the application can interpret.
  139.  
  140. This mechanism may work, but it is not very efficient.  There is a
  141. better way to do this using WFLG_RMBTRAP.  This flag is from the Flags
  142. field in the Window structure.  When set, this flag disables menu
  143. operations for the window.  When the user hits the menu button,
  144. Intuition sends the window IDCMP_MOUSEBUTTONS events instead of menu
  145. events.
  146.  
  147. To use WFLG_RMBTRAP as an alternative to menu verify, the application
  148. tracks mouse movement using IDCMP_MOUSEMOVE.  While the pointer is
  149. outside of the screen's title bar, the application makes sure the
  150. WFLG_RMBTRAP flag is set.   If the user hits the right mouse button
  151. while WFLG_RMBTRAP is set, Intuition sends the application a mouse
  152. button event.  While the pointer is inside the screen's title bar, the
  153. application makes sure the WFLG_RMBTRAP flag is clear.  If the user
  154. hits the right mouse button while WFLG_RMBTRAP is clear, Intuition
  155. generates a normal menu event for the window.
  156.  
  157. WFLG_RMBTRAP is an exception to most fields in Intuition structures
  158. because it is legal for an application to directly modify this flag.
  159. Note that this change must take place as an atomic operation so that
  160. Exec cannot perform a task switch in the middle of the change.  If you
  161. are unsure your compiler will do this, use a Forbid()/Permit() pair to
  162. prevent a task switch.
  163.  
  164. There are cases where an application is too busy to handle any menu
  165. event so it needs to prevent menu operations for a while.  This is
  166. another case where menu verify is inappropriate.  A better way to block
  167. menus is to remove the menu with the Intuition function
  168. ClearMenuStrip() and restore it later with ResetMenuStrip().  Another
  169. potentially useful way to block menu operations is using a requester.
  170.  
  171.  
  172. Will I Ever Need to Cancel a Menu Operation?
  173.  
  174. When the active window receives an IDCMP_MENUVERIFY message, it has the
  175. option of cancelling the menu operation.  Although this feature may
  176. have some possible uses, for the moment there is no recommended use for
  177. it.
  178.  
  179.  
  180. Handling Menu Verify Events
  181.  
  182. Typically, an application uses menu verify because the application
  183. needs to know when the menus are down.  This goes for the menus of any
  184. window on the screen, not just the application's window.  When the
  185. application receives its IDCMP_MENUVERIFY message, it performs some
  186. minor processing (restoring menu pen colors, for example) and records
  187. the fact that the display is in a ``menu processing'' state (i.e.
  188. Intuition is going to display the menus).  The application then returns
  189. the menu verify message so Intuition can continue with the menu
  190. operation.  The application cannot utilize the screen's resources until
  191. the menu processing state is over.
  192.  
  193. There are two types of events that can end the menu processing state.
  194. A cancellation or a menu pick can terminate the menu processing state.
  195.  
  196. There are several events that can cancel a menu operation.  Some
  197. possibilities include Intuition timing out waiting for an outstanding
  198. IDCMP_MENUVERIFY, the active window cancelling the menu operation, and
  199. Intuition failing to allocate enough resources to display the menus.
  200. The ``Intuition Menus'' chapter of the Amiga ROM Kernel Manual:
  201. Libraries attempts to interpret these causes based on the IDCMP
  202. messages that arrive after the application returns the IDCMP_MENUVERIFY
  203. message.
  204.  
  205. The book should not have mentioned how to interpret the cause of a menu
  206. cancellation.  The reasoning for the cancellation is not really
  207. relevant.  Trying to interpret the cause of a menu cancellation is a
  208. bad idea (especially if you interpret based on the information in the
  209. book; it's wrong).  The only important fact is that the ``menu
  210. processing'' state has terminated and the application can resume normal
  211. operations.
  212.  
  213. Any of the following message combinations signify the cancellation of
  214. the ``menu processing'' state:
  215.  
  216.   o IDCMP_MOUSEBUTTONS (IntuiMessage.Code is equal to MENUUP) only
  217.   o IDCMP_MENUPICK (IntuiMessage.Code is equal to MENUNULL) only
  218.   o IDCMP_MOUSEBUTTONS (IntuiMessage.Code is equal to MENUUP) then
  219.       IDCMP_MENUPICK (IntuiMessage.Code is equal to MENUNULL)
  220.   o IDCMP_MENUPICK (IntuiMessage.Code is equal to MENUNULL) then
  221.       IDCMP_MOUSEBUTTONS (IntuiMessage.Code is equal to MENUUP)
  222.  
  223. Since the active window can cancel menu operations, the application may
  224. need to determine if its window is the active window.  The application
  225. can do this by examining the IntuiMessage.Code field of the menu verify
  226. message.  If that field is equal to MENUWAITING (defined in
  227. <intuition/intuition.h>) the window is not active.  However, if that
  228. field is equal to MENUHOT (defined in <intuition/intuition.h>) the
  229. window is active and can cancel the menu operation by changing the Code
  230. field of the menu verify message to MENUCANCEL (also defined in
  231. <intuition/intuition.h>).  If the application cancels the menu
  232. operation, Intuition will send the active window an IDCMP_MOUSEBUTTONS
  233. event about the right mouse button.
  234.  
  235. The following are possible cases signifying that the ``menu
  236. processing'' state is over because the user successfully pulled down
  237. and released the menu (there was no cancellation):
  238.  
  239.   o IDCMP_MENUPICK (IntuiMessage.Code is equal to the menu code)
  240.   o (spurious) IDCMP_MOUSEBUTTONS (IntuiMessage.Code is equal to MENUUP)
  241.       then IDCMP_MENUPICK (IntuiMessage.Code is equal to the menu code)
  242.  
  243. Note that the menu code could be MENUNULL if no item was selected.
  244. IDCMP_MENUHELP events have the same meaning as the IDCMP_MENUPICK
  245. messages when it comes to terminating the ``menu processing'' state.
  246.  
  247. There are rare cases in 3.0 and prior, where Intuition does not send
  248. the application an IDCMP message after the user picks a menu item.  The
  249. result is the application does not know that the ``menu processing''
  250. state is over.  The only notable case is when the user types a menu
  251. keyboard shortcut, and Intuition times out waiting for the application
  252. to respond to the menu verify message.
  253.  
  254. V40 should fix the lack of a terminating event in those rare cases, as
  255. well as eliminate the spurious IDCMP_MOUSEBUTTONS event that can occur
  256. for successful menu picks.
  257.  
  258.  
  259. About Double Menu Requesters
  260.  
  261. Intuition has a feature that allows an application to put up a special
  262. type of requester when the user double clicks the right mouse button.
  263. This requester is known as a Double Menu Requester.  Unfortunately, the
  264. double menu requester is considered to be inconsistant with the Amiga's
  265. user interface, so using them in any capacity is strongly discouraged.
  266. Using them in conjunction with menu verify is even more strongly
  267. discouraged because they significantly complicate processing menu
  268. verify events.  For this reason, never use double menu requester and
  269. menu verify together!
  270.